<?php
class agents_property
{
	protected	$_group = 1;
	protected	$_limit = 12;
	protected	$_role_id = 107;
	protected	$_DBconn;
	protected	$_front_template;
	protected	$_view;
	protected	$translator;
	
	public function __construct($view) 
	{
		$this->_front_template = Zend_Registry::get('front_template'); 
		$this->_view =	$view;
		
		//DB Connection
		$this->_DBconn = Zend_Registry::get('msqli_connection');
		$this->_DBconn->getConnection();
		
		$this->translator = Zend_Registry::get('translator');
	}
	
function property_truncate($phrase,$start_words, $max_words)
{
   $phrase_array = explode(' ',$phrase);
   if(count($phrase_array) > $max_words && $max_words > 0)
	  $phrase = implode(' ',array_slice($phrase_array, $start_words, $max_words)).'...';  
   return $phrase;
}
	public function class_body()
	{
		$translator = Zend_Registry::get('translator');	
		$select = $this->_DBconn->select()
									->from(array('up' => Zend_Registry::get('dbPrefix').'user_profile'), array('up.user_id','title' => 'up.title', 'city' => 'up.city', 'state' => 'up.state', 'firstName' => 'up.firstName', 'lastName' => 'up.lastName', 'register_date' => 'up.register_date', 'companyName' => 'up.companyName', 'address' => 'up.address', 'phone' => 'up.phone', 'mobile' => 'up.mobile', 'fax' => 'up.fax'))
									->where('up.role_id = ?', $this->_role_id)
									->where('up.status = ?', '1')
									->group('up.user_id')
									->limit($this->limit)
                                                                        ->joinLeft(array('tt' => Zend_Registry::get('dbPrefix').'property_page'), 'tt.property_owner = up.user_id', array('property_num' => 'COUNT(*)'))
									->joinLeft(array('pp' => Zend_Registry::get('dbPrefix').'countries'), 'pp.id = up.country', array('country' => 'pp.value'));
                		
		$view_datas =  $select->query()->fetchAll();
	?>
   
    	<?php
		if($view_datas)
		{
			foreach($view_datas as $entry)
			{
		?>
        <div class="block">
			<div class="list">        	
				<ul>
                    <li>
                    	<a href="<?php echo $this->_view->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'agents','property_owner' => $this->_view->escape($entry['user_id']) ),'Agent-Property-List/:property_owner',true); ?>" class="preview" link="" title="<?php echo $this->translator->translator('property_front_page_agent_search_property_no', $entry['register_date'], 'Property'); ?>"><?php if($entry['companyName']){ echo $this->_view->escape($entry['companyName']); } ?></a><br />
                    	
                        <?php echo $this->_view->escape($entry['title'].' '.$entry['firstName'].' '.$entry['lastName']).'<br />'; ?>
                        <?php if($entry['address']){ echo $this->_view->escape($entry['address']).'<br />'; } ?>
                      <?php if($entry['country'] || $entry['city'] || $entry['state']){ echo $this->_view->escape($entry['city'].', '.$entry['state'].', '.$entry['country']).'<br />'; } ?>
                    	<?php if($entry['phone']){ echo $this->_view->escape($entry['phone']).'<br />'; } ?>
             
		    </li>
                                  
				</ul>
         	</div>
		</div>
		<?php
			}
		}
		?>

	<?php
	}
}
?>


<?php
try
{
	$agents_property_class = new agents_property($this);
	$agents_property_class->class_body();
}
catch(Exception $e)
{
	echo $e->getMessage();
}
?>
